<?php

class My_details extends Admin_Controller {

	function __construct()
	{
		parent::__construct();	
	}
	
	public function index()
	{
		
		$this->aPageJs[] = array(
							'combine_js' => true,
							'base_href' => '/media/js',
							'js' => array('admin_my_details'),
							'version' => '1.0'
		);	

		// build up our header_css array
		/*$this->aPageCss[] = array(
							'combine_css' => true,
							'base_href' => '/media/css',
							'css' => array('jquery_treeview', 'admin_menu_order'),
							'media' => 'all',
							'version' => '1.0'
		);*/		
		
		
		$this->load->model('db/users', 'users');
		
		$this->users->clear();
		
		$this->users->user_id = $this->user->userId;
		
		$qUser = $this->users->get(1);
		
		if ($qUser->num_rows() === 1)
		{
			$this->aData['oUser'] = $qUser->row(0);
			
			$this->load->view('platform/'.$this->sPlatform.'/admin/my_details/index', $this->aData);
		}
	}
	
	
	public function ajax() 
	{
		$this->sSkinFile = 'ajax';
		
		$sFunc = $this->uri->segment(4, false);
		
		if (($sFunc !== false) && (method_exists($this, $sFunc) === true))
		{
			$this->$sFunc();
				
		}
		
		return;
	}
	
	
	
	private function save_my_details()
	{
		$sUserFirstName = $this->input->post('sUserFirstName', true, '');
		$sUserLastName = $this->input->post('sUserLastName', true, '');
		$sUserEmail = $this->input->post('sUserEmail', true, '');
		$sUserPasswd = $this->input->post('sUserPasswd', true, '');
		$sUserPasswdChk = $this->input->post('sUserPasswdChk', true, '');
		
		
		$this->load->model('db/users', 'users');
		
		$this->users->clear();
		
		$this->users->user_id = $this->user->userId;
		$this->users->user_fname = $sUserFirstName;
		$this->users->user_lname = $sUserLastName;
		$this->users->user_email = $sUserEmail;
		
		if (($sUserPasswd !== '') && ($sUserPasswd === $sUserPasswdChk))
		{
		
			$this->users->user_passwd = md5($sUserPasswd);
		}
		
		
		$this->users->save();
		
		$this->aData['json_encode'] = array('sContent' => $this->aMessages['admin_my_details_saved']);
		
		$this->load->view('php_json_encode', $this->aData);
		
		
	}
	
}

?>